package com.lemon.smartsafety.ui.activity.safe.inspection;

import android.os.Bundle;
import android.support.v4.app.Fragment;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.BundleKey;
import com.lemon.smartsafety.app.EventTag;
import com.lemon.smartsafety.entity.safe.company.CompanyBuildingIndexVo;
import com.lemon.smartsafety.entity.safe.company.CompanyBuildingItemCountVo;
import com.lemon.smartsafety.entity.safe.company.CompanyBuildingVo;
import com.lemon.smartsafetynew.ui.activity.base.BaseFragmentActivity;
import com.lemon.smartsafety.ui.fragment.safe.inspection.CheckItemListFragment;
import com.zhy.http.okhttp.OkHttpUtils;

/**
 * 安全巡查 检查项目 一览表
 */
public class SafeInspectionCheckItemListActivity extends BaseFragmentActivity {
    //private LoggerHelper loggerHelper = new LoggerHelper(SafeInspectionCheckItemListActivity.class);

    private CheckItemListFragment mFragment;

    /**
     * bundle info
     */
    private CompanyBuildingVo          mCompanyBuildingVo;
    private CompanyBuildingIndexVo     mCompanyBuildingIndexVo;
    private CompanyBuildingItemCountVo mCompanyBuildingItemCountVo;


    @Override
    protected void getBundleArgs() {
        super.getBundleArgs();
        if (getIntent().getExtras() != null) {
            mCompanyBuildingVo = (CompanyBuildingVo) getIntent().getSerializableExtra(BundleKey.COMPANY_BUILD_INFO);
            mCompanyBuildingIndexVo = (CompanyBuildingIndexVo) getIntent().getSerializableExtra(BundleKey.COMPANY_BUILDING_INDEX_VO);
            mCompanyBuildingItemCountVo = (CompanyBuildingItemCountVo) getIntent().getSerializableExtra(BundleKey.COMPANY_BUILDING_ITEM_COUNT);
        }
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_fragment_swipe_no_back;
    }

    @Override
    protected void initViews() {
        super.initViews();
    }

    @Override
    public Fragment getFragment() {
        return getFragment("");
    }


    public Fragment getFragment(String text) {
        Bundle bundle = new Bundle();
        if (null != text) {
            bundle.putString(BundleKey.KEY_WORD, text);
        }
        bundle.putSerializable(BundleKey.COMPANY_BUILD_INFO, mCompanyBuildingVo);
        bundle.putSerializable(BundleKey.COMPANY_BUILDING_ITEM_COUNT, mCompanyBuildingItemCountVo);
        bundle.putSerializable(BundleKey.COMPANY_BUILDING_INDEX_VO, mCompanyBuildingIndexVo);
        mFragment = CheckItemListFragment.newInstance();
        mFragment.setArguments(bundle);
        return mFragment;
    }


    @Override
    protected void initTitle() {
        this.setBarTitle(R.string.safe_title);
    }




    /****************************************************************************************************************
     * 保护现场
     ****************************************************************************************************************/
    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putSerializable(BundleKey.COMPANY_BUILD_INFO, mCompanyBuildingVo);
        outState.putSerializable(BundleKey.COMPANY_BUILDING_ITEM_COUNT, mCompanyBuildingItemCountVo);
        outState.putSerializable(BundleKey.COMPANY_BUILDING_INDEX_VO, mCompanyBuildingIndexVo);
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        if (savedInstanceState != null) {
            mCompanyBuildingVo = (CompanyBuildingVo) savedInstanceState.getSerializable(BundleKey.COMPANY_BUILD_INFO);
            mCompanyBuildingIndexVo = (CompanyBuildingIndexVo) savedInstanceState.getSerializable(BundleKey.COMPANY_BUILDING_INDEX_VO);
            mCompanyBuildingItemCountVo = (CompanyBuildingItemCountVo) savedInstanceState.getSerializable(BundleKey.COMPANY_BUILDING_ITEM_COUNT);
        }
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        OkHttpUtils.getInstance().cancelTag(EventTag.TAG_SAFE_DATA_COLLECTION_BUILDING_CHECK_ITEM_LIST);
        mCompanyBuildingVo = null;
        mCompanyBuildingIndexVo = null;
        mCompanyBuildingItemCountVo = null;


       /* try {
            BuildingPositionRefreshEvent refreshEvent=new BuildingPositionRefreshEvent();
            refreshEvent.setTag(BuildingPositionRefreshEvent.class.getName());
            AppService.getBus().post(refreshEvent);
        } catch (Exception e) {
            e.printStackTrace();
        }*/

    }
}
